/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 *
 * @author blz
 */
public class MenuBar extends JMenuBar implements ActionListener {
    
    private Window window;
    
    public MenuBar(Window window)
    {
        this.window = window;
        
        JMenu menuTetravex = new JMenu("Tetravex");
        menuTetravex.setMnemonic( 'T' );
        super.add(menuTetravex);
        
        this.agregarMenuItem(menuTetravex, "Nuevo", 'N');
        this.agregarMenuItem(menuTetravex, "Puntuacion", 'P');
        menuTetravex.addSeparator();
        
        JMenu menuTamanio = new JMenu("Tamanio");
        this.agregarMenuItem(menuTamanio, "2x2", ' ');
        this.agregarMenuItem(menuTamanio, "3x3", ' ');
        this.agregarMenuItem(menuTamanio, "4x4", ' ');
        this.agregarMenuItem(menuTamanio, "5x5", ' ');
        this.agregarMenuItem(menuTamanio, "6x6", ' ');
        
        menuTetravex.add(menuTamanio);
        
        this.agregarMenuItem(menuTetravex, "Salir", 's');
        
        JMenu menuAbout = new JMenu("Ayuda");
        menuAbout.setMnemonic( 'B' );
        this.agregarMenuItem(menuAbout, "About", 'a');
        super.add(menuAbout);    
    }
    
    public void agregarMenuItem( JMenu parent, String caption, char mnemonic )
    {
        JMenuItem item = new JMenuItem(caption);
        item.setMnemonic(mnemonic);
        item.setActionCommand(caption);
        item.addActionListener(this);
        parent.add(item);
    }

    @Override
    public void actionPerformed(ActionEvent ae) {

        switch(ae.getActionCommand())
        {
            case "About":
                         
                         Dialog dig = new Dialog("About");
                         dig.setcontenido(new About());
                         dig.setLocationRelativeTo(this.window);
                         dig.setVisible(true);
                    break;
        }
    }
}
